package workers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.concurrent.BlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JOptionPane;

import workerUIs.StepFrame;
import workerUIs.TestFrame;
import workflow.step.ArchitectureDesignStep;
import model.Software;

public class TestStepWorker extends AbstractStepSwingWorker {
	
	public TestStepWorker(StepFrame frame, String inputQueueName,
			String outputQueueName) {
		super(frame, inputQueueName, outputQueueName);
	}


	
	@Override
	protected void doStep(Software software) {		
		//This step does not modify the Software object.
	}
	
	public static void main(String[] args)
	{
		Logger logger = Logger.getLogger(TestStepWorker.class.getCanonicalName());
		
		try
		{			
			final TestFrame testFrame = new TestFrame("If block: Testing", 1200, 600);			
			
			testFrame.getNextButton().addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					/**
					 * User decision: if tests were successful, then the next step will be 'Release Step'.
					 * 				  Otherwise, next step is 'Repair Step', and 'Release Step' comes after it.
					 */
					String outputQueueName = null;
					switch (JOptionPane.showConfirmDialog(testFrame, "Tests succcessful?")) {
					case JOptionPane.YES_OPTION: 
						testFrame.setTestSuccessful(true);
						outputQueueName = IMQConstants.RELEASE_INPUT;
						break;
					default: 
						testFrame.setTestSuccessful(false);
						outputQueueName = IMQConstants.TEST_OUTPUT_REPAIR_INPUT;
						break;
					}
					new TestStepWorker(testFrame, IMQConstants.INTEGRATION_OUTPUT_TEST_INPUT, outputQueueName).execute();				
				}
			});
			new QueueDepthObserver().observeQueueDepth(testFrame, IMQConstants.INTEGRATION_OUTPUT_TEST_INPUT);
		}
		catch (Exception e)
		{
			logger.log(Level.SEVERE, "Error during initialization: ", e);
		}
	}

}
